a=int(input())
s1="stroka"
s2="stroka"
s3="stroka"
s4="stroka"
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
i8=0
i9=0
i10=0
i11=0
i12=0
i13=0
i14=0
i15=0
q1=0
q2=0
q3=0
q4=0
q5=0
q6=0
q7=0
q8=0
q9=0
q10=0
q11=0
q12=0
q13=0
q14=0
q15=0
w=0
if 999<a<10000:
    s1=str((a//1000)%10)
    s2=str((a//100)%10)
    s3=str((a//10)%10)
    s4=str(a%10)
    i1 = int(s1)
    for i in range(2,i1):
        if i1%i==0:
            q1 += 1
    if q1==0:
        i1=i1
    else:
        i1=0
    i2 = int(s2)
    for i in range(2,i2):
        if i2%i==0:
            q2 += 1
    if q2 == 0:
        i2 = i2
    else:
        i2 = 0
    i3 = int(s3)
    for i in range(2,i3):
        if i3%i==0:
            q3+=1
    if q3==0:
        i3=i3
    else:
        i3=0
    i4 = int(s4)
    for i in range(2,i4):
        if i4%i==0:
            q4 += 1
    if q4==0:
        i4=i4
    else:
        i4=0
    i5 = int(s1+s2)
    for i in range(2,i5):
        if i5%i==0:
            q5 += 1
    if q5==0:
        i5=i5
    else:
        i5=0
    i6 = int(s2+s3)
    for i in range(2,i6):
        if i6%i==0:
            q6 += 1
    if q6==0:
        i6=i6
    else:
        i6=0
    i7 = int(s3+s4)
    for i in range(2,i7):
        if i7%i==0:
            q7 += 1
    if q7==0:
        i7=i7
    else:
        i7=0
    i8 = int(s1+s2+s3)
    for i in range(2,i8):
        if i8%i==0:
            q8 += 1
    if q8==0:
        i8=i8
    else:
        i8=0
    i9 = int(s2+s3+s4)
    for i in range(2,i9):
        if i9%i==0:
            q9 += 1
    if q9==0:
        i9=i9
    else:
        i9=0
    i10 = int(s1+s2+s4)
    for i in range(2,i10):
        if i10%i==0:
            q10 += 1
    if q10==0:
        i10=i10
    else:
        i10=0
    i11 = int(s1+s3+s4)
    for i in range(2,i11):
        if i11%i==0:
            q11 += 1
    if q11==0:
        i11=i11
    else:
        i11=0
    i12 = int(s1+s3)
    for i in range(2,i12):
        if i12%i==0:
            q12 += 1
    if q12==0:
        i12=i12
    else:
        i12=0
    i13 = int(s1+s4)
    for i in range(2,i13):
        if i13%i==0:
            q13 += 1
    if q13==0:
        i13=i13
    else:
        i13=0
    i14 = int(s2+s4)
    for i in range(2,i14):
        if i14%i==0:
            q14 += 1
    if q14==0:
        i14=i14
    else:
        i14=0
    i15 = int(s1+s2+s3+s4)
    for i in range(2,i15):
        if i15%i==0:
            q15 += 1
    if q15==0:
        i15=i15
    else:
        i15=0
    if i1>max(i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15):
        w=i1
    elif i2>max(i1, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15):
        w=i2
    elif i3>max(i1, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15):
        w=i3
    elif i4>max(i1, i3, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15):
        w=i4
    elif i5>max(i1, i3, i4, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15):
        w=i5
    elif i6>max(i1, i3, i4, i5, i7, i8, i9, i10, i11, i12, i13, i14, i15):
        w=i6
    elif i7>max(i1, i3, i4, i5, i6, i8, i9, i10, i11, i12, i13, i14, i15):
        w=i7
    elif i8>max(i1, i3, i4, i5, i6, i7, i9, i10, i11, i12, i13, i14, i15):
        w=i8
    elif i9>max(i1, i3, i4, i5, i6, i7, i8, i10, i11, i12, i13, i14, i15):
        w=i9
    elif i10>max(i1, i3, i4, i5, i6, i7, i8, i9, i11, i12, i13, i14, i15):
        w=i10
    elif i11>max(i1, i3, i4, i5, i6, i7, i8, i9, i10, i12, i13, i14, i15):
        w=i11
    elif i12>max(i1, i3, i4, i5, i6, i7, i8, i9, i10, i11, i13, i14, i15):
        w=i12
    elif i13>max(i1, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i14, i15):
        w=i13
    elif i14>max(i1, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i15):
        w=i14
    elif i15>max(i1, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14):
        w=i15
    else:
        w=0
    print(w)
else:
    print(0)

